package com.xidian.zhiancloud.service.riskcontrol;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xidian.zhiancloud.dao.riskcontrol.TriskWarSingManaStaMapper;
import com.xidian.zhiancloud.model.riskcontrol.TriskWarSingManaStaList;
import com.xidian.zhiancloud.model.riskcontrol.entity.TWarSingManaStaEntity;
import com.xidian.zhiancloud.qo.BaseReqQuery;
import org.apache.commons.beanutils.ConvertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 风险管控-风险警示标志管理
 */
@Service
public class TriskWarSingManaStaService  extends ServiceImpl
        <TriskWarSingManaStaMapper, TriskWarSingManaStaList> {

    @Autowired
    TriskWarSingManaStaMapper triskWarSingManaStaMapper;

    public Page<TriskWarSingManaStaList> getTriskWarSingManaStaList(
            BaseReqQuery reqdata,String isCondition,Long companyId){
        PageHelper.startPage(reqdata.getPageNum(), reqdata.getPageSize());
        return triskWarSingManaStaMapper.getTriskWarSingManaStaList(
                reqdata.getSearchKey(), isCondition, companyId);
    }

    public int addTriskWarSingManaSta
            (TriskWarSingManaStaList tRiskWarSingManaSta){
        return triskWarSingManaStaMapper.addTriskWarSingManaSta
                (tRiskWarSingManaSta);
    }

    public int updateTriskWarSingManaSta(String id,
          TriskWarSingManaStaList tRiskWarSingManaSta){
        return triskWarSingManaStaMapper.updateTriskWarSingManaSta
            (id,tRiskWarSingManaSta);
    }

    public int deleteTriskWarSingManaSta(String id){
        List<String> list = getList(id);
        return triskWarSingManaStaMapper.deleteTriskWarSingManaSta(list);
    }

    /**
     * id放入list
     * @param id id(多个已逗号分隔)
     * @return List集合
     */
    public List<String> getList(String id) {
        List<String> list = new ArrayList<String>();
        String[] str = id.split(",");
        for (int i = 0; i < str.length; i++) {
            list.add(str[i]);
        }
        return list;
    }

    public List<TriskWarSingManaStaList> getByTWarSingManaStaList(String id){
        return triskWarSingManaStaMapper.getByTWarSingManaStaList(id);
    }

    public Page<TriskWarSingManaStaList> getExportTWarSingManaStaData
            (Long companyId,String id){
        List<Object> list = getObjeList(id);
        return triskWarSingManaStaMapper.getExportTWarSingManaStaData
                (companyId,list);
    }

    public List<Object> getObjeList(String ids) {
        List<Object> list = new ArrayList<Object>();
        String[] str = ids.split(",");
        long[] strArrNum = (long[]) ConvertUtils.convert(str,long.class);
        for (Long id : strArrNum) {
            list.add(id);
        }
        return list;
    }

    public int addSingManaStaEntity(Long companyId,Long userId,List<TWarSingManaStaEntity> wsiManList){
        return triskWarSingManaStaMapper.addSingManaStaEntity
                (companyId,String.valueOf(userId),wsiManList);
    }


}
